package com.ymatou.iapi.exp.testcase;

import java.util.ArrayList;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.exp.parameter.AddUserExpBean;
import com.ymatou.iapi.exp.parameter.OrderEvaluationNoticeBean;
import com.ymatou.iapi.exp.service.OrderEvaluationNoticeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ExpCallService;
import com.ymttest.database.sqlwapper.ExpWapper;


/**
 * 获取用户未评价订单的可获得的总经验值 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_OrderEvaluationNotice {
	private static OrderEvaluationNoticeBean orderevaluationnoticeBean;
	private static OrderEvaluationNoticeCall orderevaluationnoticeCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取用户未评价订单的可获得的总经验值");
	}

	@Before
	public void caseUp() {
		orderevaluationnoticeBean = new OrderEvaluationNoticeBean();
		orderevaluationnoticeCall = new OrderEvaluationNoticeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(orderevaluationnoticeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_OrderEvaluationNotice_001() {
		Logger.start(true, "获取用户未评价订单的可获得的总经验值成功");
		try {
			int uid = 101;
			ExpCallService.resetExp(uid, 0);
			AddUserExpBean addexpbean = ExpCallService.addExp(uid, 50, 100102);
			ArrayList<String> orderIdList = new ArrayList<String>();
			orderIdList.add(addexpbean.getBizNo());
			orderevaluationnoticeBean.setUserId(uid);
			orderevaluationnoticeBean.setOrderIdList(orderIdList);
			orderevaluationnoticeCall.setData(orderevaluationnoticeBean);
			orderevaluationnoticeCall.callService();
			Logger.verifyEquals("success", orderevaluationnoticeCall.getString("errorMessage"), "验证errormessage");
			Logger.verifyEquals("true", orderevaluationnoticeCall.getString("success"), "验证success");
			Logger.verifyEquals("0", orderevaluationnoticeCall.getString("errorCode"), "验证ErrorCode");
			Integer exp = orderevaluationnoticeCall.getJsonObject().getAsJsonObject("result").get("exp").getAsInt();
			Logger.verifyEquals(10, exp, "验证exp");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_OrderEvaluationNotice_002() {
		Logger.start(true, "获取用户多个未评价订单的可获得的总经验值成功");
		try {
			int uid = 102;
			ExpCallService.resetExp(uid, 0);
			ArrayList<String> orderIdList = new ArrayList<String>();
			for (int i = 0; i < 5; i++) {
				AddUserExpBean addexpbean = ExpCallService.addExp(uid, 50, 100102);
				orderIdList.add(addexpbean.getBizNo());
			}
			orderevaluationnoticeBean.setUserId(uid);
			orderevaluationnoticeBean.setOrderIdList(orderIdList);
			orderevaluationnoticeCall.setData(orderevaluationnoticeBean);
			orderevaluationnoticeCall.callService();
			Logger.verifyEquals("success", orderevaluationnoticeCall.getString("errorMessage"), "验证errormessage");
			Logger.verifyEquals("true", orderevaluationnoticeCall.getString("success"), "验证success");
			Logger.verifyEquals("0", orderevaluationnoticeCall.getString("errorCode"), "验证ErrorCode");
			Integer exp = orderevaluationnoticeCall.getJsonObject().getAsJsonObject("result").get("exp").getAsInt();
			Logger.verifyEquals(50, exp, "验证exp");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_OrderEvaluationNotice_003() {
		Logger.start(true, "获取用户未评价但是金额不足20订单的可获得的总经验值成功");
		try {
			int uid = 103;
			ExpCallService.resetExp(uid, 0);
			AddUserExpBean addexpbean = ExpCallService.addExp(uid, 10, 100102);
			ArrayList<String> orderIdList = new ArrayList<String>();
			orderIdList.add(addexpbean.getBizNo());
			orderevaluationnoticeBean.setUserId(uid);
			orderevaluationnoticeBean.setOrderIdList(orderIdList);
			orderevaluationnoticeCall.setData(orderevaluationnoticeBean);
			orderevaluationnoticeCall.callService();
			Logger.verifyEquals("success", orderevaluationnoticeCall.getString("errorMessage"), "验证errormessage");
			Logger.verifyEquals("true", orderevaluationnoticeCall.getString("success"), "验证success");
			Logger.verifyEquals("0", orderevaluationnoticeCall.getString("errorCode"), "验证ErrorCode");
			Integer exp = orderevaluationnoticeCall.getJsonObject().getAsJsonObject("result").get("exp").getAsInt();
			Logger.verifyEquals(0, exp, "验证exp");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_OrderEvaluationNotice_004() {
		Logger.start(true, "不输入uid，无经验");
		try {
			int uid = 103;
			ExpCallService.resetExp(uid, 0);
			AddUserExpBean addexpbean = ExpCallService.addExp(uid, 60, 100102);
			ArrayList<String> orderIdList = new ArrayList<String>();
			orderIdList.add(addexpbean.getBizNo());
//			orderevaluationnoticeBean.setUserId(uid);
			orderevaluationnoticeBean.setOrderIdList(orderIdList);
			orderevaluationnoticeCall.setData(orderevaluationnoticeBean);
			orderevaluationnoticeCall.callService();
			Logger.verifyEquals("success", orderevaluationnoticeCall.getString("errorMessage"), "验证errormessage");
			Logger.verifyEquals("true", orderevaluationnoticeCall.getString("success"), "验证success");
			Logger.verifyEquals("0", orderevaluationnoticeCall.getString("errorCode"), "验证ErrorCode");
			Integer exp = orderevaluationnoticeCall.getJsonObject().getAsJsonObject("result").get("exp").getAsInt();
			Logger.verifyEquals(0, exp, "验证exp");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_OrderEvaluationNotice_005() {
		Logger.start(true, "不输入orderIdList无经验");
		try {
			int uid = 103;
			ExpCallService.resetExp(uid, 0);
			AddUserExpBean addexpbean = ExpCallService.addExp(uid, 70, 100102);
//			ArrayList<String> orderIdList = new ArrayList<String>();
//			orderIdList.add(addexpbean.getBizNo());
			orderevaluationnoticeBean.setUserId(uid);
//			orderevaluationnoticeBean.setOrderIdList(orderIdList);
			orderevaluationnoticeCall.setData(orderevaluationnoticeBean);
			orderevaluationnoticeCall.callService();
			Logger.verifyEquals("success", orderevaluationnoticeCall.getString("errorMessage"), "验证errormessage");
			Logger.verifyEquals("true", orderevaluationnoticeCall.getString("success"), "验证success");
			Logger.verifyEquals("0", orderevaluationnoticeCall.getString("errorCode"), "验证ErrorCode");
			Integer exp = orderevaluationnoticeCall.getJsonObject().getAsJsonObject("result").get("exp").getAsInt();
			Logger.verifyEquals(0, exp, "验证exp");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_OrderEvaluationNotice_006() {
		Logger.start(true, "获取历史评价订单exp成功");
		try {
			Map m=new ExpWapper().selectOrderPrice1();
			if(m==null){
				throw new Exception("历史评价订单exp数据Order_Price为空,请插入前置条件");
			}
			
			int uid = 106;
			ArrayList<String> orderIdList = new ArrayList<String>();
			orderIdList.add(m.get("OrderId").toString());
			orderevaluationnoticeBean.setUserId(uid);
			orderevaluationnoticeBean.setOrderIdList(orderIdList);
			orderevaluationnoticeCall.setData(orderevaluationnoticeBean);
			orderevaluationnoticeCall.callService();
			Logger.verifyEquals("success", orderevaluationnoticeCall.getString("errorMessage"), "验证errormessage");
			Logger.verifyEquals("true", orderevaluationnoticeCall.getString("success"), "验证success");
			Logger.verifyEquals("0", orderevaluationnoticeCall.getString("errorCode"), "验证ErrorCode");
			Integer exp = orderevaluationnoticeCall.getJsonObject().getAsJsonObject("result").get("exp").getAsInt();
			Logger.verifyEquals(Double.valueOf((Double.valueOf(m.get("Price").toString())*0.2)).intValue(), exp, "验证exp");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_OrderEvaluationNotice_007() {
		Logger.start(true, "产线验证");
		try {
			int uid = 1643065;
			ArrayList<String> orderIdList = new ArrayList<String>();
			orderIdList.add("122114478");
			orderevaluationnoticeBean.setUserId(uid);
			orderevaluationnoticeBean.setOrderIdList(orderIdList);
			orderevaluationnoticeCall.setData(orderevaluationnoticeBean);
			orderevaluationnoticeCall.callService();
			Logger.verifyEquals("success", orderevaluationnoticeCall.getString("errorMessage"), "验证errormessage");
			Logger.verifyEquals("true", orderevaluationnoticeCall.getString("success"), "验证success");
			Logger.verifyEquals("0", orderevaluationnoticeCall.getString("errorCode"), "验证ErrorCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}